package com.lyz.ehcachedome;

import com.lyz.ehcachedome.entity.User;
import com.lyz.ehcachedome.service.EhcacheService;
import com.lyz.ehcachedome.service.impl.EhcacheServiceImpl;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@ContextConfiguration(locations = {"classpath:spring/applicationContext.xml",
                                    "classpath:spring/applicationContext-ehcache.xml"})

@RunWith(SpringJUnit4ClassRunner.class)
public class SpringEhcacheText {

    @Autowired
    private EhcacheService ehcacheService;

    @Test
    public void testFindById(){
        User byId = ehcacheService.findById("213102");
        System.out.println("----------------");
        ehcacheService.findById("213102");
    }

    @Test
    public void testCachePut(){
        User mimmi = ehcacheService.insert(new User("2231564", "mimmi"));
        System.out.println("在缓存中取数据");
        User byId = ehcacheService.findById("2231564");
        System.out.println(byId);
    }

    @Test
    public void testCacheEvict(){
        ehcacheService.findById("213102");
        System.out.println("--------------");
        ehcacheService.deleteById("213102");
        System.out.println("--------------");
        ehcacheService.findById("213102");
    }
}
